package aole.util;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;

public class ColorButton extends JButton {

	private static final long	serialVersionUID	= 1L;

	private Color				color;

	public ColorButton() {
		this( Color.black );
	}

	public ColorButton( Color c ) {
		super( " " );
		
		setFocusable( false );
		setFocusPainted( false );
		setColor( c );
		
		addActionListener( new ActionListener() {
			@Override
			public void actionPerformed( ActionEvent e ) {
				showColorDialog();
			}
		} );
	}

	private void showColorDialog() {
		setColor( JColorChooser.showDialog( this, "Set Color", color ) );
	}

	public void setColor( Color c ) {
		color = c;
		setBackground( c );
	}

	public Color getColor() {
		return color;
	}
}
